﻿using System;

namespace direction
{
    internal class Program
    {
        /// <summary>
        /// 每个数字代表一个方向，随机生成数字，进入switch循环中，随后用readkey读取输入的字符，判断正误
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            DateTime begintime = DateTime.Now;
            int erroy = 0;
            for (int i = 0; i < 10; i++)
            {
                Console.Clear();
                Random rnd = new Random();
                int output = rnd.Next(1, 5);
                char input = 'a';
                switch (output)
                {
                    case 1:
                        Console.WriteLine("up");
                        input = 'w';
                        break;
                    case 2:
                        Console.WriteLine("down");
                        input = 's';
                        break;
                    case 3:
                        Console.WriteLine("left");
                        input = 'a';
                        break;
                    case 4:
                        Console.WriteLine("right");
                        input = 'd';
                        break;

                }
                char x = Console.ReadKey().KeyChar;
                if (x != input)
                    erroy++;
                Console.Clear();

            }
            //计时器
            Console.WriteLine($"错误的次数是{erroy}");
            DateTime endtime = DateTime.Now;
            TimeSpan Time = endtime.Subtract(begintime);
            Console.WriteLine("用时{0}", Time.TotalSeconds);
        }
    }
}